const {
  MarketingModel
} = require('../../../../utils/marketing-model.js');
var marketingModel = new MarketingModel();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    prizeState: 3,
    popupsModel: false,
    selectType: "", //0奖品 1碎片
    activityId: "", //核销记录id || 奖品id
    ficationInfo: {}, //核销信息
    fragmentData: [], //碎片列表
    activityStatus: "", //活动状态
    activityEndDate:'',//时间
    activityCardType:'',//活动类型
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      selectType: options.type, //0奖品 1碎片
      activityId: options.activityId,
      activityStatus: options.activityStatus,
      activityCardType: options.activityCardType || '',
    }, function () {
      this.getPrizeInfo();
    })
  },

  /**
   * 查询奖品碎片
   */
  getPrizeInfo: function () {
    if (this.data.selectType == "0") { //核销
      this.getVerificationGet();
    } else if (this.data.selectType == "1") {
      this.getFragmentDetail(); //碎片详情
    }
  },

  /**
   * 奖品核销详情
   */
  getVerificationGet: function (type) {
    wx.showLoading({
      title: '加载中',
      mask: true
    });
    var param = {};
    param.merchantId = wx.getStorageSync('merchantId'); //商户ID
    param.activityVerificationId = this.data.activityId; //核销记录id
    param.activityCardType = this.data.activityCardType; //活动类型：1：集卡活动一期 2：全国活动 3：达人机活动 5：瓜分游戏币活动
    marketingModel.verificationGet(param).then(data => {
      this.setData({
        ficationInfo: data,
        activityEndDate: data.partitionCoinLotteryDate ? data.partitionCoinLotteryDate.substr(0, 4) + "年" + data.partitionCoinLotteryDate.substr(5, 2) + "月" + data.partitionCoinLotteryDate.substr(8, 2) + "日 " + data.partitionCoinLotteryDate.substr(11, 8) : ""
      });
    }).catch(err => {
      wx.showToast({
        title: `${err.error}`,
        icon: 'none',
        duration: 2000
      })
    })
  },

  /**
   * 奖品碎片详情
   */
  getFragmentDetail: function (type) {
    var param = {};
    param.merchantId = wx.getStorageSync('merchantId'); //商户ID
    param.activityAwardId = this.data.activityId; //奖品id
    marketingModel.fragmentDetail(param).then(data => {
      this.setData({
        fragmentData: data
      });
    }).catch(err => {
      wx.showToast({
        title: `${err.error}`,
        icon: 'none',
        duration: 2000
      })
    })
  },
  /**
   * 去点亮
   */
  goGompound: function () {
    var param = {};
    param.merchantId = wx.getStorageSync('merchantId'); //商户ID
    param.activityAwardId = this.data.activityId; //奖品id
    marketingModel.memberLight(param).then(data => {
      if (data) {
        this.setData({
          activityId: data.activityVerificationId,
          activityInfo: data,
          popupsModel: true
        });
      } else {
        this.setData({
          activityInfo: {},
          popupsModel: false
        });
      }
    }).catch(err => {
      wx.showToast({
        title: `${err.error}`,
        icon: 'none',
        duration: 2000
      })
    })
  },
  //去点亮
  closeIllume() {
    this.setData({
      popupsModel: false,
    }, function () {
      wx.setStorageSync('prizeSelectType', 0);
      wx.navigateBack({
        delta: 1
      })
    })
  },
  /**
   * 去兑奖台兑换
   */
  goPrizeCancellation: function () {
    wx.redirectTo({
      url: `/pages/memberCenter/prize/prizeCancellation/index?activityVerificationId=${this.data.activityId}`
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  closeGather() {
    this.setData({
      popupsModel: false
    })
  },
})